import { observable, action } from 'mobx';
import { WeaTableNew } from 'comsMobx';
import { message } from 'antd';
import { WeaLocaleProvider } from 'ecCom';
import * as Api from '../../apis/docWorkflowApi/docVersionApi';

const { TableStore } = WeaTableNew;
const getLabel = WeaLocaleProvider.getLabel;

class DocVersionStore {
  @observable tableStore = new TableStore();
  @observable versionId = '';
  @observable docid = '5410';
  @observable iswps = ''


  @action.bound
  getList() {
    const params = {
      docid: this.docid,
      iswps: this.iswps,
    };
    Api.getList(params).then((data) => {
      if (data.api_status) {
        this.tableStore.getDatas(data.sessionkey);
      }
    });
  }

  @action.bound
  onOperatesClick(record, index, operate, flag) {
    if (flag == '1') {
      window.open(`${window.location.protocol}//${window.location.host}/weaver/weaver.file.FileDownload?download=1&fileid=${record.imageFileId}`);
    } else if (flag == '2') {
      this.deleteVersion(record);
    }
  }

	@action.bound
  deleteVersion(record) {
    const params = {
      method: 'delImgsOnly',
      docid: record.docid,
      delcurrentversion: '1',
      delImgIds: record.imageFileId,
    };
    Api.delVersion(params).then((data) => {
      if (data.api_status) {
        this.getList();
        message.success(getLabel('20461', '删除成功'));
      }
    });
  }

  @action.bound
  setVersionId(versionId) {
  	this.versionId = versionId;
  }

  @action.bound
  setDocid(docid) {
  	this.docid = docid;
  }

  @action.bound
  setIswps(iswps) {
    this.iswps = iswps;
  }
}

export default DocVersionStore;
